package com.example.mapper;

import com.example.dto.Goods;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * <P> @Author: SongKeCheng
 * <P> Description:
 * <P> Type: Interface
 * <P> Date: 2024/12/16:16:24
 */

public interface GoodsMapper {
    public List<Goods> allGoods();


    @Results(
            {
                    @Result(property = "id", column = "id"),
                    @Result(property = "name", column = "name"),
                    @Result(property = "author", column = "author"),
                    @Result(property = "publisher", column = "publisher"),
                    @Result(property = "pubtime", column = "pubtime"),
                    @Result(property = "categoryid", column = "categoryid"),
                    @Result(property = "description", column = "description"),
            }
    )
    @Select("select * from goods")
    //@Delete()
    //@Insert()
    //@Update()
    public List<Goods> allGoods2();

    public Goods findById(Integer id);


    Goods findByIdAndAuthor(Map<Object, Object> params);

    int addGoods(Goods goods);

    //更新 根据id 更新名字和 编号
    int updateGoods(Goods goods);

    //删除 根据id 删除数据
    int deleteGoods(String id);

    //根据作者名称模糊查询
    List<Goods> findByAuthor(String author);


    //分页查询
    public List<Goods> findByPage(Map<String, Object> map);

    //方法参数绑定
    Goods findByIdAndAuthor2(@Param("id") Integer id,
                             @Param("author") String author);

    //方法参数绑定 有对象，还有普通入参
    Goods findByIdAndAuthorObj(@Param("goods") Goods goods,
                               @Param("author") String userName);

    //根据id 或者 作者模糊查询
    List<Goods> findByIdAndAuthorIf(Goods goods);

    //根据id 或者 作者模糊查询 使用where + if 标签
    List<Goods> findByIdAndAuthorWhere(Goods goods);

    //    <!--    如果id 满足条件 查询id=？-->
    //    <!--    如果id 不满足条件，author 满足条件，查询author=？-->
    //    <!--    上面都不满足，查询 id=1-->
    List<Goods> findByIdAndAuthorChoose(Goods goods);


    public List<Goods> findNoOrMore(Goods goods);

    //传入多个id，查询对应的id 返回
    List<Goods> findByIdsForeach(@Param("ids") List<Integer> ids);

    //批量修改指定id数据 的状态
    int updateGoodsStatusIn(Map<String, Object> map);


    //查询商品信息时 查询类别详情
    public Goods findGoodsAndCategoryById(Integer id);
}
